{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "\"\"\" 鸡兔同笼\n",
    "一个笼子里关有若干只鸡，兔子，已经知道总脚数 a， 则笼子里至少有多少只动物，至多有多少只动物？\n",
    "# 输入数据： 一个正整数 n (n<=1000)，表示测试数据的组数n,接下来n组数据一行，每一行一个正整数a（a<=32768)\n",
    "# 输出要求：包含n行，每行对应一个输入，包含2个正整数，第一个是最少动物数，第二个是最多动物数，用空格分开，如果没有满足的答案，用0 表示\n",
    " \"\"\"\n",
    "# 兔子和鸡必须同时存在的情况，枚举法，容易超时\n",
    "def count_animal(n):\n",
    "    rabit = 4\n",
    "    chiken = 2\n",
    "    for  i in range(1,n+1):\n",
    "        for j in range(i, n+1):\n",
    "            if 4*i + 2*j == n:\n",
    "                print(f\"rabit: {i}, chiken: {j}\")\n",
    "            else: \n",
    "                print(f\"rabit: 0, chiken: 0\")\n",
    "\n",
    "# 模拟分析法\n",
    "def count_animal_like(n):\n",
    "    nFeets = 4\n",
    "    nCases = 2\n",
    "    while (1):\n",
    "        nCases = nCase=int(input(\"测试数据行数： \"))\n",
    "        if not nCases:\n",
    "            break\n",
    "        for case in range(0, nCases):\n",
    "            nFeets = int(input(\"总脚数： \"))\n",
    "            if nFeets % 4 == 0:\n",
    "                print(f\"min: {nFeets // 4}, max:{nFeets // 2}\")\n",
    "            elif nFeets % 2 == 0:\n",
    "                min = (nFeets // 4) + 1 if nFeets >=4 else 1\n",
    "                print(f\"min: {min}, max:{nFeets // 2}\")\n",
    "            else:\n",
    "                print(f\"min: {0}, max:{0}\")\n",
    "\n",
    "count_animal_like(100)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
